// pages/news/news.js
var api = require("../../api/api.js");
var utils = require("../../utils/utils.js");
var id;
var num;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isHidden: true,
    mPageNum: 1,
    newsList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    id = options.news_id;
    id = 1
    if (utils.isEmpty(id)) {
      return;
    }
    this.getList()

  },
  getList: function () {
    api.default.api('get_news', { "page": this.data.mPageNum }, this.successCallback, this.errorCallback);
  },
  successCallback: function (e) {
    this.setData({
      isHidden: true,
    });
    if (e.data.length == 0) {
      this.data.mPageNum -= 1;
      return;
    };

    this.setData({
      newsList: this.data.newsList.concat(e.data)
    });

    wx.stopPullDownRefresh() //停止下拉刷新
    wx.hideNavigationBarLoading()
  },

  /**
   * jump to richText
   */
  newsDetailTap: function (e) {
    wx.navigateTo({
      url: 'newsDetail/newsDetail?news_id=' + e.currentTarget.id,
    })
  },

  errorCallback: function (e) {


  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.data.mPageNum = 1;
    this.data.newsList=[]
    this.getList();
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      isHidden: false
    });
    this.data.mPageNum += 1;
    this.getList()


  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})